using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace Bll
{
	class CCommodityManage
	{
		public static CCommodity CreateCommodity()
       {      
           return   new CCommodity();
       }
	   
	   public static CCommodity Save(CCommodity commodity)
	   {
			try
           {
               int num = BLL.SqlHelper.ExecuteNonQuery(CConnection.getConnString(), "sp_AddCommodity", commodity.ID, commodity.name, commodity.ownerID,
                   commodity.ownerType, commodity.status, commodity.pic, commodity.Category, commodity.commodityID, commodity.Quantity,
                   commodity.RetailPrice, commodity.StartPrice, commodity.CostPrice, commodity.ShipFees, commodity.Title, commodity.introduction);
             
				if(0 == num)
                   return null;
                return commodity;
           }
           catch (Exception e)
           {
               return null;
           }
	   }
	   
	   public static bool Update(CCommodity commodity)
	   {
			try
			{
                int num = BLL.SqlHelper.ExecuteNonQuery(CConnection.getConnString(), "sp_SaveCommodity", commodity.ID, commodity.name, commodity.ownerID,
                   commodity.ownerType, commodity.status, commodity.pic, commodity.Category, commodity.commodityID, commodity.Quantity,
                   commodity.RetailPrice, commodity.StartPrice, commodity.CostPrice, commodity.ShipFees, commodity.Title, commodity.introduction);
				if (0 == num)
                   return false;
				return true;
			}
			catch (Exception e)
			{
               return false;
			}
	   }
	   
	   public static bool Delete(CCommodity commodity)
	   {
			try
			{
                int num = BLL.SqlHelper.ExecuteNonQuery(CConnection.getConnString(), "sp_RemoveCommodity", commodity.ID, commodity.name, commodity.ownerID,
                   commodity.ownerType, commodity.status, commodity.pic, commodity.Category, commodity.commodityID, commodity.Quantity,
                   commodity.RetailPrice, commodity.StartPrice, commodity.CostPrice, commodity.ShipFees, commodity.Title, commodity.introduction);
				if (0 == num)
                   return false;
				return true;
			}
			catch (Exception e)
			{
               return false;
			}
	   }
	   
	   static CCommodity GetCommodity(String ID)
	   {
           SqlDataReader reader = BLL.SqlHelper.ExecuteReader(CConnection.getConnString(), "sp_GetCommodity", ID);
			try
           {
               
               if (reader.Read())
               { 
					CCommodity commodity = new CCommodity();
					commodity.name = reader["name"].ToString();
					commodity.introduction = reader["introduction"].ToString();
				//	commodity.price = reader["price"].ToString();
					commodity.ownerID = reader["ownerID"].ToString();
				//	commodity.ownerType = reader["ownerType"].ToString();
				//	commodity.status = reader["status"].ToString();
					commodity.pic = reader["pic"].ToString();
					
		
					return commodity;
               }
			
               return null;
           }
           catch (Exception e)
           {

               //reader.Close();
               return null;
           }
            finally
            {
                reader.Close();
            }
	   }
	}
}